import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '主页', icon: 'dashboard' }
    }]
  },

  {
    path: '/authority',
    component: Layout,
    redirect: '/authority/account',
    name: 'Authority',
    alwaysShow: true,
    meta: { title: '权限管理', icon: 'auth' },
    children:[
      {
        path: 'account',
        name: 'Account',
        component: () => import('@/views/authority/account/index'),
        meta: { title: '账号管理', icon: 'account' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/authority/role/index'),
        meta: { title: '角色管理', icon: 'role' }
      },
      {
        path: 'resource',
        name: 'Resource',
        component: () => import('@/views/authority/resource/index'),
        meta: { title: '资源管理', icon: 'menu' }
      },
    ]
  },
  
  {
    path: '/product',
    component: Layout,
    redirect: '/product/list',
    name: 'Product',
    alwaysShow: true,
    meta: { title: '商品管理', icon: 'el-icon-s-shop' },
    children:[
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/product/list/index'),
        meta: { title: '商品列表', icon: 'el-icon-shopping-bag-2' }
      },
      {
        path: 'newList',
        name: 'NewList',
        hidden:true,
        component: () => import('@/views/product/list/newList/index'),
        meta: { title: '编辑列表', icon: 'el-icon-shopping-bag-2',activeMenu:"/product/list" }
      },
      {
        path: 'category',
        name: 'Category',
        component: () => import('@/views/product/category'),
        meta: { title: '商品分类', icon: 'el-icon-menu' }
      },
      {
        path: 'brand',
        name: 'Brand',
        component: () => import('@/views/product/brand'),
        meta: { title: '品牌管理', icon: 'el-icon-present' }
      },
    ]
  },

  {
    path: '/order',
    component: Layout,
    redirect: '/order/orderList',
    name: 'Order',
    alwaysShow: true,
    meta: { title: '订单管理', icon: 'el-icon-tickets' },
    children:[
      {
        path: 'orderList',
        name: 'OrderList',
        component: () => import('@/views/order/orderList/index'),
        meta: { title: '订单列表', icon: 'el-icon-document-checked' }
      },
      {
        path: 'seeOrder',
        name: 'SeeOrder',
        hidden:true,
        component: () => import('@/views/order/orderList/seeOrder/index'),
        meta: { title: '查看订单', icon: 'el-icon-shopping-bag-2',activeMenu:'/order/orderList'}
      },
      {
        path: 'quitList',
        name: 'QuitList',
        component: () => import('@/views/order/quitList/index'),
        meta: { title: '退单列表', icon: 'el-icon-document-delete'}
      },
      {
        path: 'checkRefund',
        name: 'CheckRefund',
        hidden:true,
        component: () => import('@/views/order/quitList/checkRefund/index'),
        meta: { title: '查看退单', icon: 'el-icon-shopping-bag-2',activeMenu:'/order/quitList'}
      },
      {
        path: 'adminAddress',
        name: 'AdminAddress',
        component: () => import('@/views/order/adminAddress/index'),
        meta: { title: '地址管理', icon: 'el-icon-school'}
      }
    ]
  },

  {
    path: '/register',
    component: Layout,
    redirect: '/register/registerUser',
    name: 'Register',
    alwaysShow: true,
    meta: { title: '注册用户管理', icon: 'el-icon-s-custom' },
    children:[
      {
        path: 'registerUser',
        name: 'RegisterUser',
        component: () => import('@/views/register/registerUser/index'),
        meta: { title: '用户列表', icon: 'el-icon-user' }
      }
    ]
  },

  {
    path: '/market',
    component: Layout,
    redirect: '/market/limitActive',
    name: 'Market',
    alwaysShow: true,
    meta: { title: '营销管理', icon: 'el-icon-goods' },
    children:[
      {
        path: 'limitActive',
        name: 'LimitActive',
        component: () => import('@/views/market/limitActive/index'),
        meta: { title: '限时活动', icon: 'el-icon-files' }
      },
      {
        path: 'ad',
        name: 'Ad',
        component: () => import('@/views/market/ad/index'),
        meta: { title: '广告列表', icon: 'el-icon-document-copy' }
      }
    ]
  },

  {
    path: '/content',
    component: Layout,
    redirect: '/content/article',
    name: 'Content',
    alwaysShow: true,
    meta: { title: '内容管理', icon: 'el-icon-folder' },
    children: [
      {
        path: 'article',
        name: 'Article',
        component: () => import('@/views/content/article/index'),
        meta: { title: '文章管理', icon: 'el-icon-document' }
      },
      {
        path: 'addText',
        name: 'AddText',
        hidden:true,
        component: () => import('@/views/content/article/detail/index'),
        meta: { title: '新增文章', icon: 'table',activeMenu: '/content/article' }
      },
      {
        path: 'editext/:id',
        name: 'EditText',
        hidden:true,
        component: () => import('@/views/content/article/detail/index'),
        meta: { title: '编辑文章', icon: 'table',activeMenu: '/content/article' }
      },
      {
        path: 'material',
        name: 'Material',
        component: () => import('@/views/content/material/index'),
        meta: { title: '素材管理', icon: 'el-icon-picture' }
      },
    ]
  },

 

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
